package api

import (
	"chat_oa/api/handler"
	"chat_oa/api/middleware"
	"chat_oa/consts"
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
)

func LoadRoutes(r *gin.Engine) {
	r.GET("/ping", handler.Ping)
	r.Use(middleware.Cors())
	api := r.Group("/api")
	{
		admin := api.Group("/admin")
		{
			admin.POST("/add", handler.AddUser)
			admin.GET("/getOnlineUser", handler.GetOnlineUser)
		}
		user := api.Group("/user")
		{
			user.POST("/login", handler.Login)
		}
		chat := api.Group("/chat")
		{
			chat.Use(gojwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)
			chat.GET("/list", handler.GetChatList)
		}
		group := api.Group("/group")
		{
			group.Use(gojwt.JWTAuth(consts.JWT_KEY))
			group.POST("/addGroup", handler.AddGroup)
			group.POST("/addGroupUser", handler.AddGroupUser)
			group.POST("/setAuth", handler.SetAuth)
			group.POST("/removeUser", handler.RemoveUser)
			group.POST("/delGroup", handler.DelGroup)
		}
	}
}
